//
// OpenTemplate
// Copyright (c) 2006
// by OpenArrow Software ( http://www.openarrow.com )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
//

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;
using System.IO;
using OpenArrow.Reporting;

namespace OpenArrow.Templating.Parsing
{
    /// <summary>
    /// Provides an interface to a Template Parser, which is a type responsible for parsing a
    /// textual representation of a template into a <see cref="ParsedTemplate"/> object.
    /// </summary>
    /// <remarks>
    /// <para>Here is a short example for using template parsers and generators:</para>
    /// <example language="C#">
    /// <code>
    /// using System;
    /// using System.IO;
    /// 
    /// using OpenArrow.Templating.Parsing;
    /// using OpenArrow.Templating.Compilation;
    ///  
    /// public class MyQuickGenerator() 
    /// {
    /// 	public static void Main(string[] args)
    /// 	{
    ///         // Create the parser and generator
    ///         ITemplateParser parser = new ASPNetStyleTemplateParser();
    ///         ITemplateGenerator generator = new StandardTemplateGenerator();
    ///         
    ///         // Open a file stream and stream reader for the template
    ///         FileStream stream = new FileStream("MyTemplate.template", FileAccess.Read);
    ///         StreamReader reader = new StreamReader(stream);
    /// 
    ///         // Parse the template
    ///         TemplateParserResults parserResults = parser.Parse(reader);
    /// 
    ///         // Check for problems
    ///         if(!parserResults.Success)
    ///         {
    ///             Console.WriteLine("Errors Occurred!");
    ///             return;
    ///         }
    /// 
    ///         // Generate a CodeCompileUnit from the template
    ///         TemplateGeneratorResults generatorResults = generator.Generate(parserResults.Output, "MyTemplate.template");
    /// 
    ///         // Check for problems
    ///         if(!parserResults.Success)
    ///         {
    ///             Console.WriteLine("Errors Occurred!");
    ///             return;
    ///         }
    /// 
    ///         // Do what you want with the Compile Unit now!
    ///     }
    /// }
    /// </code>
    /// </example>
    /// <example language="VB">Coming Soon!</example>
    /// <example language="C++">Sorry, no C++ examples are available. Use the C# example as a basis.</example>
    /// </remarks>
    public interface ITemplateParser
    {
        /// <summary>
        /// Parses the specified template source file
        /// </summary>
        /// <param name="input">The input reader to read the template from</param>
        /// <returns>The results of the parsing operation</returns>
        /// <exception cref="OpenArrow.Templating.ActionProblemsException">A large number of errors occurred in the operation and it had to be aborted</exception>
        /// <exception cref="System.IO.IOException">An I/O error occurs</exception>
        /// <exception cref="ArgumentNullException"><paramref name="input"/> is <see langword="null"/></exception>
        TemplateParserResults Parse(TextReader input);

        /// <summary>
        /// Parses the specified template source file
        /// </summary>
        /// <remarks>This method reports its progress to a given progress reporter</remarks>
        /// <param name="input">The input reader to read the template from</param>
        /// <param name="reporter">The progress reporter to report to</param>
        /// <returns>The results of the parsing operation</returns>
        /// <exception cref="OpenArrow.Templating.ActionProblemsException">A large number of errors occurred in the operation and it had to be aborted</exception>
        /// <exception cref="System.IO.IOException">An I/O error occurs</exception>
        /// <exception cref="ArgumentNullException"><paramref name="input"/> is <see langword="null"/></exception>
        TemplateParserResults Parse(TextReader input, IProgressReporter reporter);
    }
}
